<style type="text/css">
<!--
    #Content {
        width: 100% !important; 
    }
    div.divRight {
        float: right;
        width: 99.7%;
        border: 1px solid #ED7600;
    }
    
	
    
    div.info_game{
        color: black;
    }
    div.info_game > table {
        width: 100%;
    }
   
    table.point_exchange {
        width: 80%;
        border: 1px solid #a5b4b7;
        font-weight: normal !important;
        color: black;
        text-align: center;
    }
    table.point_exchange th{
        background-color: #a5b4b7;
        padding: 5px;
        color: white;
    }
    table.point_exchange td{
        
        padding: 5px;
        
    }
    /*so chan */
    table.point_exchange tr.even
    {
        
    }
    /*so le*/
    table.point_exchange tr.odd{   
        background-color: #84E4EA;
    }
    
-->
</style>
<script type="text/javascript">
<!--
    
    var _point_exchange = JSON.parse('<?=mysql_real_escape_string(json_encode($point_exchange))?>');
	function moneyToPoint(money)
    {
        var point = money;
        var index = -1;
        for(var i =0 ;i< _point_exchange.length; i++)
        {
            if (Number(_point_exchange[i].money_amount) > Number(money))
            {
                index = i-1;
                break;
            }
            else if (Number(_point_exchange[i].money_amount) == Number(money))
            {
                index = i;
                break;
            }
            else if (_point_exchange.length == i+1 && Number(money) > Number(_point_exchange[i].money_amount))
            {
                index = i;
                break;
            }
        } 
        if (index == -1)
        {
            //get value index 0
            if (_point_exchange.length == 0)
            {
                //no exchange
                point = money; 
            }
            else
            {
                //exchange
                var point_sys = _point_exchange[0].point;
                var money_sys = _point_exchange[0].money_amount;
                point = money * point_sys / money_sys;
            }
        }
        else 
        {
            //get value last
            var point_sys = _point_exchange[index].point;
            var money_sys = _point_exchange[index].money_amount;
            point = money * point_sys / money_sys;
        }
        
        $('#msg_coin').html("You will be add <b style='color:red;'>" + parseInt(point) + "</b> points on your account.");
    }
    function check_conditions_and_next()
    {
        if ($('input[type=radio]:checked').length == 1)
        {
            $('#msg').empty();
            $('table[name=step1]').hide();
            $('table[name=step2]').show();
        }
        else
        {
            $('#msg').empty();
            $('#msg').append('<div class="error"><span>You have not selected.</span></div>');
        }
    }
    function back_step()
    {
        $('#msg').empty();
        $('table[name=step2]').hide();
        $('table[name=step1]').show();
    }
    function change_country(obj)
    {
        var country_id = obj.value;
        $.get( '/pay/ajax_getStatesByCountryId/' + country_id, function( content ) {
            if (content == '')
            {
                $('input[name=createPaymentHasState]').val('no');
                $('input[name=createPaymentBillStateText]').show();
                $('select[name=createPaymentBillState]').hide();
            }
            else
            {
                $('input[name=createPaymentHasState]').val('yes');
                $('input[name=createPaymentBillStateText]').hide();
                $('select[name=createPaymentBillState]').show();
                $('select[name=createPaymentBillState]').html(content);
            }
            
        });
    }
    function process()
    {
        $('#buy_points').submit();
    }
    function create_new_payment_account()
    {
        $("input[name=option_payment]").val("new");
        $("table[name=payment_account]").hide();
        $("table[name=new_payment_account]").show();
    }
    function choose_old_payment_account()
    {
        $("input[name=option_payment]").val("old");
        $("table[name=payment_account]").show();
        $("table[name=new_payment_account]").hide();
    }
    
-->
</script>
<style type="text/css">
<!--
	h3.title {
	    color: #0A4874;
        font-weight: bold;
        border-bottom: 1px dashed #D5D5D5;
        padding-bottom: 10px;
        padding-left: 10px;
	}
-->
</style>
<div class="divRight">
    <?=$menu?>
    
    <h3 class="title">.::. Buy More Points</h3>
    
    <?=$showInfoPlayer?>
    
    <style type="text/css">
<!--
	div.info_game {
	   padding: 10px;
       padding-top: 0px;
       /*color: #0A4874;
       font-weight: bold;*/
	}
    div.info_game input[type=radio]{
        height: 0px;
    }
    table.input td.label{
        text-align: center;
    }
    
-->
</style>
    <div class="info_game">
        <div id="msg">
        <?php if( isset($BuyResult) && $BuyResult == false): ?>
            <div class="error"> <span><?=$BuyMessage?></span></div>
        <?php elseif (isset($BuyResult) && $BuyResult == true):?>
            <div class="success"><span><?=$BuyMessage?></span></div>
        <?php endif; ?>
        </div>
        
        
        
        <?php if (isset($point_exchange) && count($point_exchange) > 0) : ?>
        
        <form id="buy_points" method="POST" style="padding-top: 10px;">
        <table name='step1' style="width:30%;">
            <tr>
                <td>
                    <p><span>How many points you want to buy?</span></p>
                </td>
            </tr>
            <?php foreach($point_exchange as $coin){ ?>
            <tr>
                <td style="vertical-align: middle;">
                    <input type="radio" name="money" value="<?=$coin->money_amount?>"/> 
                    <span>$<?=round($coin->money_amount,2)?> for <?=(int)$coin->point?> points</span>
                </td>
            </tr>
            <?php } ?>
            <tr>
                <td style="text-align: right;">
                    <input type="hidden" name="action" value="Next" />
                    <input type="button" onclick="check_conditions_and_next()" class="button" value="Next" />
                </td>
            </tr>
        </table>
        
        <table name='step2' style="width:70%;display:none;">
            <tbody>
    		
    		<tr>
    			<td colspan="2">
                
<!-- payment account -->
                <?php if (count($paymentAccounts) > 0): ?>
                <table name="payment_account" style="width:90%" class="pageContent">
					<tbody>
                        <tr>
  			               <td colspan="2" class="heading" id="heading"><p>&nbsp;Billing Address &amp; Payment Account</p></td> 
   		               </tr>	
                        <tr>
				   		 	<td valign="top" class="notReq">Payment account:</td>
				   		 	<td>
                                <select name="paymentAccount" onchange="javascript:changeFrebPaymentAccount()" id="paymentAccount">  
                                <?php foreach($paymenttransactions as $paymenttransaction){ ?>
                                    <option value="<?=$paymenttransaction->id?>">xxxx-xxxx-xxxx-<?=$paymenttransaction->cc_last4digits?></option>                                
                                <?php } ?>                          
                                </select>
                                <span><a href="javascript:create_new_payment_account()" style="position: static;" class="subbutton">Create</a></span>
				   		 	</td>
			   		 	</tr>
						<tr>
							<td class="req"><div id="divbillAddress1"><span class="colortext">*</span>Address 1:</div></td>
							<td><input type="text" maxlength="255" size="30" value="<?=$address->street_address_1?>" name="billAddress1">                		 
			            	</td>
						</tr>
						<tr>
							<td class="notReq">Address 2:</td>
							<td><input type="text" maxlength="255" size="30" value="<?=$address->street_address_2?>" name="billAddress2"></td>
						</tr>
						<tr>
							<td class="req"><div id="divbillCountry"><span class="colortext">*</span>Country:</div></td>
							<td><select disabled="" onchange="changeCountry(this);" id="billCountryId" name="billCountry">
                                    <?php foreach($countries as $country){
                                        if($address->country == $country->id)
                                        {
                                    ?>
                                            <option value="<?=$country->id?>" selected="true"><?=$country->name?></option>
                                    <?php }
                                        else
                                        {
                                        ?>
                                            <option value="<?=$country->id?>"><?=$country->name?></option>                                
                                    <?php 
                                        } 
                                    }
                                    ?>
                                </select>
                            </td>
						</tr>	
						<tr>
							<td class="req"><div id="divbillCity"><span class="colortext">*</span>City:</div></td>
							<td><input type="text" maxlength="255" size="30" value="<?=$address->city?>" name="billCity"></td>
						</tr>
						<tr>
							<td class="req"><div id="divbillState"><span class="colortext">*</span>State/Province:</div></td>
							<td>
							<input type="text" maxlength="255" id="billStateTextId" value="<?=$address->state?>" name="billStateText">                           
                             </td>
						</tr>	
						<tr>
							<td class="req"><div id="divbillZip"><span class="colortext">*</span>Zip:</div></td>
							<td><input type="text" maxlength="9" size="9" value="<?=$address->zip_code?>" name="billZip"></td>
						</tr>	
						<tr>
							<td class="req"><div id="divbillPhone"><span class="colortext">*</span>Phone:</div></td>
							<td>(<input type="text" onkeypress="return validateKeyPressIsNumber(event);" maxlength="3" size="3" value="<?=$address->area_code?>" name="billPhone1">)
                            <input type="text" onkeypress="return validateKeyPressIsPhone(event);" maxlength="8" size="8" value="<?=$address->phone_number?>" name="billPhone2"> 
                            &nbsp;Ext
                            <input type="text" onkeypress="return validateKeyPressIsNumber(event);" maxlength="5" size="5" value="<?=$address->phone_extension?>" name="billPhone3"></td>
						</tr>					
						<tr>
							<td class="spacer" colspan="2">&nbsp;</td>
						</tr>						
					</tbody>
				</table>
                <?php endif; ?>
<!-- New payment account -->
    				<table name="new_payment_account" style="width:90%;<?=count($paymentAccounts)>0?'display:none':''?>" class="pageContent">
    					<tbody>
                            <tr>
                                <td colspan="2" class="heading" id="heading"><p>&nbsp;Provider Billing Address &amp; Payment Account
                                <?php if (count($paymentAccounts) > 0): ?>
                                <span><a href="javascript:choose_old_payment_account()" id="btnCreate" style="position: static;" class="subbutton">Choose old payment</a></span>
                                <?php endif; ?>
                                </p>
                                </td> 
                            </tr>	
                                						
                            <tr>
    							<td class="req">Choose Card Type:</td>
    							<td>
                                <select style="height:18px;width:182px;" name="createPaymentCardType">
                                    <option value="Visa">Visa</option>
                                    <option value="Master Card">MasterCard</option>
                                    <option value="Discover">Discover</option>
                                    <option value="American Express">American Express</option>
                                </select>											
                                <span class="req"><img alt="cards" src="/images/cards.jpg" class="creditCardImage" /></span>
                                </td>
    						</tr>
    						
                            <tr>
    							<td class="req">Card Holder Name:</td>
    							<td><input type="text" maxlength="255" size="30" value="" name="createPaymentName" /></td>
    						</tr>
    						
                            <tr>
    							<td class="req">Card Number:</td>
    							<td><input type="text" onblur="setCardTypeByNum(this.value, &quot;createPaymentCardType&quot;)" onkeypress="return validateKeyPressIsNumber(event);" maxlength="16" size="30" value="" name="createPaymentNumber"></td>
    						</tr>
    						   
    						<tr>
    							<td class="req">CVV Code:</td>
    							<td><input type="password" onkeypress="return validateKeyPressIsNumber(event);" maxlength="4" size="4" value="" name="createPaymentCVV2Code" /></td>
    						</tr>
    						
                            <tr>
    							<td class="req">Exp. Date</td>
    							<td>
    								<select style="height:18px;" name="createPaymentExpireMonth">
                                    <?php for ($i=1; $i<=12; $i++) echo "<option value='$i'>$i</option>" ?>
                                    </select>
                                    
    								<select style="height:18px;" name="createPaymentExpireYear">
                                        <?php $yearRange = 5; $thisYear = date('Y'); $startYear = ($thisYear + $yearRange);
                                           echo '<option value="'.$thisYear.'" selected="selected">' . $thisYear . '</option>';
                                           foreach (range($thisYear+1, $startYear) as $year) echo '<option value="'.$year.'">' . $year . '</option>'; ?>
                                    </select>							
                                    </td>
    						</tr>
                            
                            <tr>
                       		 	<td valign="top" align="left">
                                </td>
                                <td>
                                    <div class="commonFieldItem">
                                        <input type="checkbox" value="yes" name="saveCreditCard" />
                                    </div> 
                                    <div style="padding-top:4px" class="commonFieldItem">
                                        <span class="notReq" style="font-size:11px;">Save credit card</span>
                                    </div>
                       		 	</td>
                       		 </tr>
    						
            <!-- ADDRESS -->
    						<tr>
    							<td colspan="2"><br /></td>
    						</tr>
    										
    						<tr>
    							<td class="req"><div><span class="colortext">*</span>Address 1:</div></td>
    							<td><input type="text" maxlength="255" size="30" value="" name="createPaymentBillAddress1" />                		 
    			            	</td>
    						</tr>
    						<tr>
    							<td class="notReq">Address 2:</td>
    							<td><input type="text" maxlength="255" size="30" value="" name="createPaymentBillAddress2" /></td>
    						</tr>
    						<tr>
    							<td class="req"><div id="divbillCountry"><span class="colortext">*</span>Country:</div></td>
    							<td><select onchange="change_country(this);" name="createPaymentBillCountry">
                                    <?php foreach($countries as $country){?>
                                    <option value="<?=$country->id?>"><?=$country->name?></option>                                
                                    <?php } ?>
                                </select>    
                                <input type="hidden" value="<?=(count($states)==0)?'no':'yes'?>" name="createPaymentHasState" />                        
                                </td>
    						</tr>	
    						<tr>
    							<td class="req"><div id="divbillCity"><span class="colortext">*</span>City:</div></td>
    							<td><input type="text" maxlength="255" size="30" value="" name="createPaymentBillCity" /></td>
    						</tr>
    						<tr>
    							<td class="req"><div id="divbillState"><span class="colortext">*</span>State/Province:</div></td>
    							<td>
                                
                                <select name="createPaymentBillState" <?=(count($states)>0)?'':'style="display:none;"'?> >
                                <?php foreach($states as $state){?> <option value="<?=$state->id?>"><?=$state->name?></option> <?php } ?>
                                </select>
                                <input type="text" <?=(count($states)==0)?'':'style="display:none;"'?> size="15" maxlength="255" value="" name="createPaymentBillStateText" /></td>
    						</tr>	
    						<tr>
    							<td class="req"><div id="divbillZip"><span class="colortext">*</span>Zip:</div></td>
    							<td><input type="text" maxlength="9" size="9" value="" name="createPaymentBillZip" /></td>
    						</tr>	
    						<tr>
    							<td class="req"><div id="divbillPhone"><span class="colortext">*</span>Phone:</div></td>
    							<td>(<input type="text" onkeypress="return validateKeyPressIsNumber(event);" maxlength="3" size="3" value="" name="createPaymentBillPhone1" />)
                                    <input type="text" onkeypress="return validateKeyPressIsPhone(event);" maxlength="8" size="8" value="" name="createPaymentBillPhone2"/> 
                                    &nbsp;Ext
                                    <input type="text" onkeypress="return validateKeyPressIsNumber(event);" maxlength="5" size="5" value="" name="createPaymentBillPhone3"/>
                                </td>
    						</tr>					
    						<tr>
    							<td class="spacer" colspan="2">&nbsp;</td>
    						</tr>						
    					</tbody>
    				</table>			
    			</td>
    		</tr>
    		<tr>
    			<td width="32%">
                    <input type="hidden" name="option_payment" value="<?=(count($paymentAccounts)>0)?"old":"new"?>" />
                </td>
    			<td class="buttonRow">
    				<a href="javascript:process()" class="button">Process</a> &nbsp;  
    				<a href="javascript:back_step()" class="button">Back</a>
    			</td>
    		</tr>
    		<tr>
    			<td class="spacer" colspan="2">&nbsp;</td>
    		</tr>
    		<tr>
    			<td align="center" colspan="2" class="errorText"><div id="errorDiv<em></em>"></div></td>
    		</tr>
    	</tbody> 
        </table>
        </form>
        <?php endif;?>
         
        <!--<form method="POST">
            <table class="input">
                <tr>
                    <td class="label" style="width: 30%;">Money ($):</td>
                    <td><input type="text" name="money" oninput="moneyToPoint(this.value)" /></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="submit" name="action" class="button" value="Accept" /></td>
                </tr>
                <tr>
                    <td></td>
                    <td><div id="msg_coin">You will lose <b style="color:red;">0</b> points on your account.</div></td>
                </tr>
            </table>
        </form>
        -->
        <!--
        <?php if (isset($point_exchange) && count($point_exchange) > 0) : ?>
            <p>
                <span class="blue">Points exchange:</span>
            </p>
            <table class="point_exchange">
                <thead>
                    <tr>
                        <th style="width: 20%;"> No.</th>
                        <th>Money</th>
                        <th>Points</th>
                    </tr>
                </thead>
                <?php $i= 0; foreach($point_exchange as $coin){ ?>
                <tr class="<?=($i%2 ==0)?'even':'odd'?>" >
                    <td><?=++$i?></td>
                    <td>$<?=round($coin->money_amount,2)?></td>
                    <td><?=(int)$coin->point?> Points</td>
                </tr>
                <?php } ?>
            </table>
        <?php endif;?>
        -->
    </div>
        

    <!-- END POINT EXCHANGE -->
</div>


